﻿using UnityEngine;
using System.Collections;


public class GhostController : MonoBehaviour {

	public GameObject athorGhost;
	public GameObject lilithGhost;

	public Transform target;
	public float speed = 1;
	Vector3 direction;
	float distance;

	void Start () {
		target = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().ghostTarget;
	}

	// Update is called once per frame
	void Update () {

		direction =  target.position - gameObject.transform.position;

		direction=Vector3.Normalize(direction);


		distance = Vector3.Distance(gameObject.transform.position, target.transform.position);

		if(distance>3) {
			gameObject.transform.Translate(direction*speed*Time.deltaTime, Space.World);
		}

		gameObject.transform.LookAt(target.position);
		gameObject.transform.Rotate(0, 90,0, Space.Self);

	}

	public void switchGhost(PlayerController.CHARS activeChar) {
		switch(activeChar) {
		case PlayerController.CHARS.ATHOR :
			athorGhost.SetActive(false);
			lilithGhost.SetActive(true);
			break;
		case PlayerController.CHARS.LILITH :
			athorGhost.SetActive(true);
			lilithGhost.SetActive(false);
			break;
		}
	}
}
